<?

if( !$_POST[XML] ){
	echo "ERROR : Post parameter(XML) doesn't exist";
	exit;
}

if( !$_POST[RRID] ){
	echo $_POST[XML];	
	//echo "ERROR : Post parameter(RRID) doesn't exist";
	exit;
}

// rule check

$xml = new DOMDocument;
$xml->loadXML(stripslashes($_POST[XML]));

$RID = "{$_POST[RRID]}";

mysql_connect("localhost", "canss", "1022") or die("ERROR: Could not connect " . mysql_error());
mysql_select_db("rule_db");

$query = "SELECT `XSL` FROM `rule` WHERE `rid` = '$RID'";
$result = mysql_query($query);

if( !$result ){
    echo "ERROR : could not query";
    exit;
}

if( $row = mysql_fetch_row($result) ){
    $XSL = $row[0];
}
else{
    echo "ERROR : Rule doesn't exist $RID";
    exit;
}

$xsl = new DOMDocument;
$xsl->loadXML($XSL);

// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules

echo $proc->transformToXML($xml);

?>
